﻿#ifndef __CWorld__BASE__HEAD__
#define __CWorld__BASE__HEAD__

#include "server_type.h"

#include <memory>  // for unique_ptr<>
#include <set>

#include <LuaIntf/LuaIntf.h>  // for LuaContext

class CAsioServer;
class CCfgReader;
class CServerMailBox;
class CServerMailBoxMgr;

class CWorld
{
public:
	CWorld();
	virtual ~CWorld();

public:
	virtual bool init(const char* pszEtcFile);

public:
	uint16_t GetServerId();

public:
	void SetServer(CAsioServer* pSvr);
	CAsioServer* GetServer();
	CServerMailBox* GetServerMailbox(uint16_t nServerId);

public:
	inline lua_State* GetLuaState()
	{
		return m_luaCtx.state();
	}

	inline CCfgReader* GetCfgReader() const
	{
		return m_pCfg.get();
	}

	inline CServerMailBoxMgr& GetSvrMbMgr()
	{
		return *m_pSvrMbMgr;
	}

public:
	//根据server_id获取服务器绑定端口
	uint16_t GetServerPort(uint16_t sid);

protected:
	void InitMailboxMgr();
	bool DoLuaInitFile(const std::string& sLuaInitFileName);

protected:
	virtual void InitLua();

protected:
	LuaIntf::LuaContext m_luaCtx;
	std::unique_ptr<CCfgReader> m_pCfg;
	CAsioServer* m_pServer = nullptr;
	std::unique_ptr<CServerMailBoxMgr> m_pSvrMbMgr;
};

#endif  // __CWorld__BASE__HEAD__
